<template>
  <div>
    <van-address-edit
      :area-list="areaList"
      show-delete
      show-search-result
      :search-result="searchResult"
      :area-columns-placeholder="['请选择', '请选择', '请选择']"
      @save="onSave"
      @delete="onDelete"
      @change-detail="onChangeDetail"
      :address-info="info"
    />
  </div>
</template>

<script>
import { Toast } from 'vant';
import { areaList } from '@vant/area-data';
import {mapMutations} from "vuex"
export default {
  data() {
    return {
      areaList,
      searchResult: [],
      ind:-1,
       info: {
      }, //
    };
  },
  created(){
      this.ind = this.$route.query.index || -1
      console.log(this.ind)
      this.info = this.$route.query.item
  },
  methods: {
    onSave(content) {
        console.log(content)
       
      
        // 判断是新增还是编辑
        if (this.ind != -1) {

           this.editressArrPush(Object.assign({},content,{ind:this.ind}))
        } else {
             this.addressArrPush(content)
        }
        this.$router.push("/address")

    },
    onDelete(item) {
        console.log(item)
        this.shanchuAddress(this.$route.query.index)
        this.$router.push("/address")
    },
    onChangeDetail(val) {
      if (!val) {
        this.searchResult = [
          {
            name: '黄龙万科中心',
            address: '杭州市西湖区',
          },
        ];
      } else {
        this.searchResult = val;
      }
    },
    ...mapMutations(["addressArrPush","editressArrPush","shanchuAddress"])
  },
};
</script>

<style>
</style>